package me.spring.cloud.components.starter.cat.configuration;

import com.dianping.cat.Cat;
import me.spring.cloud.common.components.monitor.constant.Constant;
import me.spring.cloud.common.components.monitor.properties.CatProperties;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = Constant.cat_monitor_server_init_prefix, name = "enable", havingValue = "true")
public class ClientConfigProvider {

  @Autowired
  private CatProperties catProperties;

  @PostConstruct
  private void getCat() {
    if (!catProperties.getServers().isEmpty()) {
      String[] servers = catProperties.getServers().toArray(new String[catProperties.getServers().size()]);
      Cat.initialize(servers);
    }
  }
}
